package com.ideal.manage.esms.service.monitor;

import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;

public class ESValueSourceAggregation {
    private final String funcType;

    public ESValueSourceAggregation(String funcType) {
        this.funcType = funcType;
    }

    public ValuesSourceAggregationBuilder func(String name) {
        switch (funcType) {
            case "now":
            case "avg":
                return AggregationBuilders.avg(name);
            case "sum":
                return AggregationBuilders.sum(name);
            case "max":
                return AggregationBuilders.max(name);
            case "min":
                return AggregationBuilders.min(name);

            default:
                return null;
        }
    }
}
